package com.cdbkj.cloud.pos.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.cdbkj.cloud.pos.R;
import com.cdbkj.cloud.pos.utils.Tools;

/**
 * 选择支付方式
 */
public class PayWayFragment extends Fragment implements View.OnClickListener {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String mParam1;
    private String mParam2;

    protected View rootView;
    private Button bankCardBtn;
    private Button medicalCardBtn;
    private Button scanQrcodeBtn;

    private OnPayWayFragmentInteractionListener mListener;

    public PayWayFragment() {
        // Required empty public constructor
    }

    public static PayWayFragment newInstance(String param1, String param2) {
        PayWayFragment fragment = new PayWayFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_pay_way, container, false);
        initView(rootView);
        return rootView;
    }

    private void initView(View rootView) {
        bankCardBtn = (Button) rootView.findViewById(R.id.bank_card_btn);
        medicalCardBtn = (Button) rootView.findViewById(R.id.medical_card_btn);
        scanQrcodeBtn = (Button) rootView.findViewById(R.id.scan_qrcode_btn);
        bankCardBtn.setOnClickListener(this);
        medicalCardBtn.setOnClickListener(this);
        scanQrcodeBtn.setOnClickListener(this);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnPayWayFragmentInteractionListener) {
            mListener = (OnPayWayFragmentInteractionListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnOneFragmentInteractionListener");
        }
    }


    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.bank_card_btn) {
            mListener.onPayWayFragmentInteraction("bank_card");
        }
        else if (view.getId() == R.id.medical_card_btn) {
            mListener.onPayWayFragmentInteraction("medical_card");
        }
        else if (view.getId() == R.id.scan_qrcode_btn) {
            mListener.onPayWayFragmentInteraction("scan_qrcode");
        }
    }

    public interface OnPayWayFragmentInteractionListener {
        void onPayWayFragmentInteraction(String type);
    }
}
